//
//  PowerListData.swift
//  SCA
//
//  Created by tjun on 2025/9/7.
//

import Foundation

class PowerListModel {
    
    let title: String
    let subtitle: String
    let description: String
    let icon: String
    let total: String
    let totalDisp: String
    let icons: [String]
    let aprDisp: String
    let apr: String
    let pool: String
    
    init(title: String, subtitle: String, description: String, icon: String, total: String, totalDisp: String, icons: [String], aprDisp: String, apr: String, pool: String) {
        self.title = title
        self.subtitle = subtitle
        self.description = description
        self.icon = icon
        self.total = total
        self.totalDisp = totalDisp
        self.icons = icons
        self.aprDisp = aprDisp
        self.apr = apr
        self.pool = pool
    }
    
}

class PowerListData {
    
    let infoViewRect: CGRect
    let iconsRect: CGRect
    let descriptionRect: CGRect
    let height: CGFloat
    let attributedText: NSMutableAttributedString
    let model: PowerListModel
    
    init(model: PowerListModel) {
        self.model = model
        
        let contentW = screenWidth - AppStyle.margin.left * 2
        
        self.infoViewRect = CGRectMake(0, 0, contentW, 88)
        
        let iconsW = IconPlusView.calculateTotalWidth(iconCount: model.icons.count, iconSize: 40, plusSize: 14, spacing: 6)
        
        self.iconsRect = CGRectMake(contentW - 18 - iconsW, self.infoViewRect.maxY, iconsW, 40)
        
        let paragraphStyle = NSMutableParagraphStyle()
        paragraphStyle.lineSpacing = 3
        paragraphStyle.alignment = .left
        
        self.attributedText = NSMutableAttributedString(string: model.description, attributes: [
            .font: UIFontMake(12),
            .foregroundColor: UIColor.white,
            .paragraphStyle: paragraphStyle
        ])
        
        let maxDescriptionW = contentW - 18 - iconsW - 18 - 10
        
        let descriptionSize = self.attributedText.getSize(maxWidth: maxDescriptionW)
        self.descriptionRect = CGRectMake(18, self.iconsRect.origin.y, descriptionSize.width, descriptionSize.height)
      
        if self.descriptionRect.maxY < self.iconsRect.maxY {
            self.height = self.iconsRect.maxY + 18 + AppStyle.margin.left
        } else {
            self.height = self.descriptionRect.maxY + 18 + AppStyle.margin.left
        }
    }

}


class PurchasePowerListModel {
    
    let title: String
    let subtitle: String
    let description: String
    let poolIcon: String
    let icons: [String]
    let aprDisp: String
    let pool: String
    
    init(title: String, subtitle: String, description: String, pool: String, poolIcon: String, icons: [String], aprDisp: String) {
        self.title = title
        self.subtitle = subtitle
        self.description = description
        self.pool = pool
        self.poolIcon = poolIcon
        self.icons = icons
        self.aprDisp = aprDisp
    }
    
}

class PurchasePowerListData {
    
    let infoViewRect: CGRect
    let iconsRect: CGRect
    let descriptionRect: CGRect
    let height: CGFloat
    let attributedText: NSMutableAttributedString
    let model: PurchasePowerListModel
    
    init(model: PurchasePowerListModel) {
        self.model = model
        
        let contentW = screenWidth - AppStyle.margin.left * 2
        
        self.infoViewRect = CGRectMake(0, 0, contentW, 88)
        
        let iconsW = IconPlusView.calculateTotalWidth(iconCount: model.icons.count, iconSize: 40, plusSize: 14, spacing: 6)
        
        self.iconsRect = CGRectMake(contentW - 18 - iconsW, self.infoViewRect.maxY, iconsW, 40)
        
        let paragraphStyle = NSMutableParagraphStyle()
        paragraphStyle.lineSpacing = 3
        paragraphStyle.alignment = .left
        
        self.attributedText = NSMutableAttributedString(string: model.description, attributes: [
            .font: UIFontMake(12),
            .foregroundColor: UIColor.white,
            .paragraphStyle: paragraphStyle
        ])
        
        let maxDescriptionW = contentW - 18 - iconsW - 18 - 10
        
        let descriptionSize = self.attributedText.getSize(maxWidth: maxDescriptionW)
        self.descriptionRect = CGRectMake(18, self.iconsRect.origin.y, descriptionSize.width, descriptionSize.height)
      
        if self.descriptionRect.maxY < self.iconsRect.maxY {
            self.height = self.iconsRect.maxY + 18 + AppStyle.margin.left
        } else {
            self.height = self.descriptionRect.maxY + 18 + AppStyle.margin.left
        }
    }

}
